// pages/greeting/greeting.js  
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    topcate: [],
    sidecate: [],
    greet:[],
    tabArr: {
      curHdIndex: 0,
      curBdIndex: 0
    },
    category:[
      { id: '1', text: '朋友' ,name: 'A' },
      { id: '2', text: '恩师', name: 'B' },
      { id: '3', text: '同事', name: 'C' },
    ],
    
    greeting:[{
      name:'A',
      info:[{
        text:'A哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈',
        browse: 2910
      }, {
        text: 'A哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈',
        browse: 1256
      }, {
        text: 'A哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和哈哈哈',
        browse: 4852
      }]
    }, {
      name: 'B',
      info: [{
        text: 'B快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快',
        browse: 2356
      }, {
          text: 'B快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快',
        browse: 952
      }, {
          text: 'B快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快快',
        browse: 125
      }]
    }, {
      name: 'C',
      info: [{
        text: 'C有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义',
        browse: 2356
      }, {
        text: 'C有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义C有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义',
        browse: 952
      }, {
        text: 'C有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义有意义',
        browse: 125
      }]
    }],
    toView: '',

    curcate:0,
    curside:0,
    categoryItem: '1',
  },
  tabFun: function (e) {
    //获取触发事件组件的dataset属性 
    var _datasetId = e.target.dataset.id;
    var _obj = {};
    _obj.curHdIndex = _datasetId;
    _obj.curBdIndex = _datasetId;
    this.setData({
      tabArr: _obj
    });
  },
  scrollToViewHandle: function (e) {
    let that = this
    let id = e.currentTarget.id  
    let toView = that.data.toView
    let name = e.target.dataset.name
    let toViewNew = 'inToView' + name
    that.setData({
      toView: toViewNew,
      categoryItem:id
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.request({
      url: app.siteinfo.rootpath + 'greetlist',
      success: function (res) {
        that.setData({
          greet: res.data.greet,
          topcate: res.data.cate1,
          sidecate: res.data.cate2,
        })
      }
    })
  },
  greetHandle: function (e) {
    let that = this
    let id = e.currentTarget.id
    var topcate = that.data.topcate
    var sidecate = that.data.sidecate
    var topcateid = topcate[id]['id']
    var sidecateid = that.data.sidecateid ? that.data.sidecateid : sidecate[0]['id']
    that.setData({
      curcate:id,
      topcateid: topcateid
    })
    wx.request({
      url: app.siteinfo.rootpath + 'greetlist',
      data:{
        cid1: topcateid,
        cid2: sidecateid
      },
      success: function (res) {
        that.setData({
          greet: res.data.greet
        })
      }
    })
  },
  scrollToViewHandle: function (e) {
    let that = this
    let id = e.currentTarget.id
    var sidecate = that.data.sidecate
    var topcate = that.data.topcate
    var sidecateid = sidecate[id]['id']
    var topcateid =that.data.topcateid?that.data.topcateid: topcate[0]['id']

    that.setData({
      curside: id,
      sidecateid: sidecateid
    })
    wx.request({
      url: app.siteinfo.rootpath + 'greetlist',
      data: {
        cid1: topcateid,
        cid2: sidecateid
      },
      success: function (res) {
        that.setData({
          greet: res.data.greet
        })
      }
    })
  },
  chose:function(e){
    var that = this
    var id = e.currentTarget.id
    var greet = that.data.greet
    wx.setStorageSync('greet', greet[id]);
    wx.navigateBack({
      changed: true
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})